# See https://aka.ms/customizecontainer to learn how to customize your debug container and how Visual Studio uses this Dockerfile to build your images for faster debugging.

# This stage is used when running from VS in fast mode (Default for Debug configuration)
FROM mcr.microsoft.com/dotnet/aspnet:9.0 AS base
USER $APP_UID
WORKDIR /app
EXPOSE 9000


# This stage is used to build the service project
FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build
ARG BUILD_CONFIGURATION=Release
WORKDIR /src
COPY ["Identity/Admin/Devonline.Identity.Admin.csproj", "Identity/Admin/"]
COPY ["aspire/ServiceDefaults/Devonline.ServiceDefaults.csproj", "aspire/ServiceDefaults/"]
COPY ["AspNetCore/Core/Devonline.AspNetCore.csproj", "AspNetCore/Core/"]
COPY ["Core/Caching/Devonline.Caching.csproj", "Core/Caching/"]
COPY ["Core/Core/Devonline.Core.csproj", "Core/Core/"]
COPY ["Core/Entity/Devonline.Entity.csproj", "Core/Entity/"]
COPY ["Core/Security/Devonline.Security.csproj", "Core/Security/"]
COPY ["Core/Utils/Devonline.Utils.csproj", "Core/Utils/"]
COPY ["AuxiliaryTools/AITools/Devonline.AuxiliaryTools.AITools.csproj", "AuxiliaryTools/AITools/"]
COPY ["AuxiliaryTools/DatabaseTools/Devonline.AuxiliaryTools.DatabaseTools.csproj", "AuxiliaryTools/DatabaseTools/"]
COPY ["Database/PostgreSQL/Devonline.Database.PostgreSQL.csproj", "Database/PostgreSQL/"]
COPY ["CloudService/Aliyun/Devonline.CloudService.Aliyun.csproj", "CloudService/Aliyun/"]
COPY ["CloudService/Feige/Devonline.CloudService.Feige.csproj", "CloudService/Feige/"]
COPY ["CloudService/Tencent/Devonline.CloudService.Tencent.csproj", "CloudService/Tencent/"]
COPY ["Communication/Messages/Devonline.Communication.Messages.csproj", "Communication/Messages/"]
COPY ["Communication/Abstractions/Devonline.Communication.Abstractions.csproj", "Communication/Abstractions/"]
COPY ["Core/Logging/Devonline.Logging.csproj", "Core/Logging/"]
COPY ["Identity/Core/Devonline.Identity.csproj", "Identity/Core/"]
COPY ["Identity/Database/Devonline.Identity.Database.MySQL/Devonline.Identity.Database.MySQL.csproj", "Identity/Database/Devonline.Identity.Database.MySQL/"]
COPY ["Database/MySQL/Devonline.Database.MySQL.csproj", "Database/MySQL/"]
COPY ["Identity/Database/Devonline.Identity.Database.PostgreSQL/Devonline.Identity.Database.PostgreSQL.csproj", "Identity/Database/Devonline.Identity.Database.PostgreSQL/"]
RUN dotnet restore "./Identity/Admin/Devonline.Identity.Admin.csproj"
COPY . .
WORKDIR "/src/Identity/Admin"
RUN dotnet build "./Devonline.Identity.Admin.csproj" -c $BUILD_CONFIGURATION -o /app/build

# This stage is used to publish the service project to be copied to the final stage
FROM build AS publish
ARG BUILD_CONFIGURATION=Release
RUN dotnet publish "./Devonline.Identity.Admin.csproj" -c $BUILD_CONFIGURATION -o /app/publish /p:UseAppHost=false

# This stage is used in production or when running from VS in regular mode (Default when not using the Debug configuration)
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Devonline.Identity.Admin.dll"]